/*******************************************************************************
 * Copyright (c) 2000, 2003 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials 
 * are made available under the terms of the Common Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/cpl-v10.html
 * 
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.aseclipse.core.runtime.registry.classes {

import org.aseclipse.core.runtime.registry.IExtension;
import org.aseclipse.core.runtime.registry.IExtensionPoint;

/**
 * An object which represents the user-defined extension point in a 
 * plug-in manifest. 
 * <p>
 * This class may be instantiated, or further subclassed.
 * </p>
 */
public class ExtensionPoint extends RegistryModelObject implements IExtensionPoint {

	// DTD properties (included in plug-in manifest)
	private var id:String = null;
	// transient properties (not included in plug-in manifest)
	private var extensions:Array = null; // configured extensions, IExtension
	private var schemaReference:String;

	public function getExtensions():Array {  // IExtension[] 
		return extensions;
	}
	public function getSchemaReference():String {
		return schemaReference == null ? "" : schemaReference; //.replace("/", '/'); //$NON-NLS-1$		
	}	
	public function getSchema():String {
		return schemaReference;		
	}	
	public function getSimpleIdentifier():String {
		return id;
	}
	public function getExtension(extensionId:String):IExtension {
		if (extensionId == null)
			return null;
		if (extensions == null)
			return null;
		for (var i:int = 0; i < extensions.length; i++) {
			if (extensionId == (extensions[i] as IExtension).getUniqueIdentifier())
				return extensions[i];
		}
		return null;
	}
	public function getUniqueIdentifier():String {
		return this.getParentIdentifier() + "." + getSimpleIdentifier(); //$NON-NLS-1$
	}
	public function setExtensions(value:Array):void {
		extensions = value;
	}
	public function setSchema(schemaReference:String):void {
		assertIsWriteable();
		this.schemaReference = schemaReference;
	}
	public function setSimpleIdentifier(value:String):void {
		assertIsWriteable();
		id = value;
	}
	public function getParentIdentifier():String {
		var parent:BundleModel = getParent() as BundleModel;
		return parent.isFragment() ? parent.getHostIdentifier() : parent.getName();
	}
	public function getLabel():String {
		return getName();
		//if (s == null)
		//	return ""; //$NON-NLS-1$
		//return (getParent() as BundleModel).getResourceString(s);
	}
	
	override public function toString():String {
		return getUniqueIdentifier();
	}
}
}